package com.fucheng.transport;

import com.fucheng.common.RpcResponse;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.concurrent.atomic.AtomicReference;

public class SimpleClientHandler extends SimpleChannelInboundHandler<RpcResponse> {

    private final AtomicReference<RpcResponse> responseRef;

    public SimpleClientHandler(AtomicReference<RpcResponse> responseRef) {
        this.responseRef = responseRef;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, RpcResponse msg) {
        responseRef.set(msg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}
